<?php
namespace data\service;

use app\api\utils\ArrayUtil;
use data\model\ImgsModel;

class ImgsService extends BaseService {

    private $imgsModel = null;

    public function __construct() {
        parent::__construct();
        $this->imgsModel = new ImgsModel();
    }
    public function getImgsLists( $page , $pageSize , $where , $order = "", $fields = "*" ){
        $imgsLists = $this->imgsModel->pageQuery( $page , $pageSize , $where , $order ,$fields );
        $retData = [];
        if(!empty($imgsLists['data'])){
            foreach($imgsLists['data'] as $ck => $cv){
                $retData[$ck] = [
                    'id' => $cv['id'],
                    'url' => $cv['url'],
                    'hd' => "https://oss.ido.icu/static/" . $cv['cdn'].IMG_STYLE_W680,
                    'cdn' => "https://oss.ido.icu/static/" . $cv['cdn'].IMG_STYLE_W200,
                    'w' => $cv['w'],
                    'h' => $cv['h'],
                    'ra' => $cv['w'] / $cv['h']
                ];
            }
            return $retData;
        }
        return [];
    }

    public function imgDetail( $imgId = 0 ,$fields = "*" ){
        $imgDetail = $this->imgsModel->getInfo( ['id' => $imgId] ,$fields) ;
        $imgDetail['cdn'] = $imgDetail['cdn'].IMG_STYLE_W720;
        if(!empty($imgDetail)){
            return $imgDetail;
        }
        return [];
    }
}
